package com.flyduck.system.controller;

import com.flyduck.common.annotation.IgnoreAuth;
import com.flyduck.common.vo.PageResult;
import com.flyduck.common.vo.Result;
import com.flyduck.system.service.SysConfigService;
import com.flyduck.system.vo.config.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: flyduck-platform
 * @description:
 * @author: flyduck
 * @create: 2021-03-25 20:20
 **/
@Api(tags = "系统:参数接口")
@RestController
@RequestMapping("/system/config")
public class SysConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    @ApiOperation("获取参数分页列表")
    @PostMapping("/page")
    public Result getConfigPageList(@RequestBody SysConfigReqVO reqVo,
                                   @RequestParam(value = "page",required = true) Integer page,
                                   @RequestParam(value = "size",required = true) Integer size){
        PageResult<SysConfigRespVO> userPage = sysConfigService.getConfigPageList(reqVo, page, size);
        return Result.success(userPage);
    }

    @IgnoreAuth
    @ApiOperation("获取参数详情")
    @GetMapping("/detail")
    public Result getConfigDetail(@RequestParam(value = "id",required = true) Long id){
        SysConfigDetailRespVO respVO = sysConfigService.getConfigDetail(id);
        return Result.success(respVO);
    }

    @ApiOperation("新增参数")
    @PostMapping("/add")
    public Result addConfig(@RequestBody @Validated SysConfigAddReqVO reqVo){
        boolean flag = sysConfigService.addConfig(reqVo);
        return Result.success(flag,"新增成功");
    }

    @ApiOperation("编辑参数")
    @PutMapping("/update")
    public Result updateConfig(@RequestBody @Validated SysConfigUpdateReqVO reqVo){
        boolean flag = sysConfigService.updateConfig(reqVo);
        return Result.success(flag,"编辑成功");
    }

    @ApiOperation("删除参数")
    @DeleteMapping("/delete")
    public Result deleteConfig(@RequestParam(value = "id",required = true) Long id){
        boolean flag = sysConfigService.deleteConfig(id);
        return Result.success(flag,"删除成功");
    }

}
